﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Perceiveit.Xml.Converters
{

    #region public class PointXConverter : XConverter<Point>

    public class PointXConverter : XConverter<Point>
    {
        public static bool TryParse(string value, out Point pt)
        {
            bool success = false;
            pt = Point.Empty;
            try
            {
                int x, y;
                string[] items = value.Split(' ');
                if (items.Length == 2 && int.TryParse(items[0], out x) && int.TryParse(items[1], out y))
                {
                    pt = new Point(x, y);
                    success = true;
                }
            }
            catch (NullReferenceException)
            {

            }

            return success;
        }

        public override Point FromString(string value)
        {
            Point v;
            if (string.IsNullOrEmpty(value) || !TryParse(value, out v))
                v = Point.Empty;

            return v;
        }

        public override string ToString(Point value)
        {
            return value.X.ToString() + " " + value.Y.ToString();
        }
    }

    #endregion


}
